import os
from gevent import monkey
monkey.patch_all()

from gevent.pywsgi import WSGIServer
from geventwebsocket.handler import WebSocketHandler
from app import create_app

app = create_app()

if __name__ == '__main__':
    # 生产环境建议使用Gunicorn或uWSGI
    server = WSGIServer(
        ('0.0.0.0', 5000),
        app,
        handler_class=WebSocketHandler,
        log=None,
        error_log=app.logger
    )
    
    print(f"Server started at http://0.0.0.0:5000")
    
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        print("Server shutting down...")
        server.stop()